<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        编写一个应用程序用来输入的字符串进行加密，对于字母字符串加密规则如下：
        ‘a’→’d’ ‘b’→’e’ ‘w’→’z’ …… ‘x’→’a’ ‘y’→’b’ ‘z’→’c’‘A’→’D’ ‘B’→’E’ ‘W’→’Z’ …… ‘X’→’A’ ‘Y’→’B’ ‘Z’→’C’?对于其他字符，不进行加密。
     -->
</head>

<body>

</body>
<script>
    let str = prompt('输入一串需要加密的字符串：');
    alert('加密后的字符串是' + Encrypt(str));
    console.log(Encrypt(str));

    //字符串加密函数
    function Encrypt(str) {
        let newStr = '';
        for (let i = 0; i < str.length; i++) {
            console.log(str[i], str.charCodeAt(i));
            let a;
            //判断是否为英文字符
            if (str[i] > 'w' && str[i] <= 'z' || str[i] > 'W' && str[i] <= 'Z') {
                a = String.fromCharCode(str.charCodeAt(i) - 23);
                newStr += a;
            } else if (str[i] >= 'a' && str[i] <= 'w' || str[i] >= 'a' && str[i] <= 'W') {
                a = String.fromCharCode(str.charCodeAt(i) + 3);
                newStr += a;
            } else {
                //其他字符不进行加密变换
                newStr += str[i];
            }
        }
        return newStr;
    }
</script>

</html>